<?php if (!defined('THINK_PATH')) exit();?><!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no">
	<meta content="yes" name="apple-mobile-web-app-capable">
	<meta content="black" name="apple-mobile-web-app-status-bar-style">
	<title>添加助理</title>
    <script src="/Public/Home/js/zepto.min.js"></script>
    <link href="/Public/Home/css/weui.min.css" rel="stylesheet">
	 <link rel="stylesheet" href="/Public/Home/SaleManager/stylesheets/index.css">
	<!--  <link rel="stylesheet" href="/Public/Home/SaleManager/stylesheets/distributorindex.css"> -->
</head>
<body>
	<div class="countyInfo">
  	<header class = "all_header">
      <a class = "h_back h_back_1" href="/Home/SaleManager/Salemanager/mySaleMan/t/assistant"><img src="/Public/Home/SaleManager/images/back_icon.png" alt=""></a>
      <span class = "h_title">编辑助理</span>
      <a class = "h_add" href="javascript:void(0)"></a>
    </header>
    <form action='./addSaleman/f/page/x/nosecret' name='form1' method='POST' id='addsale'>
		<div class="weui-cells">
      <div class="weui-cell">
          <div class="weui-cell__hd"><label class="weui-label">姓名</label></div>
          <div class="weui-cell__bd">
            <input class="weui-input" type="text" name='real_name' id='real_name' placeholder="请输入姓名" value=<?php echo ($targetAssistant["real_name"]); ?>>
          </div>
      </div>
      <div class="weui-cell">
          <div class="weui-cell__hd"><label class="weui-label">手机号</label></div>
          <div class="weui-cell__bd">
              <input class="weui-input" type="number" name='phone'  id='phone' pattern="[0-9]*" placeholder="请输入手机号" value=<?php echo ($targetAssistant["phone"]); ?>>
          </div>
      </div>
      <div class="weui-cell">
        <div class="weui-cell__hd"><label class="weui-label">身份证号</label></div>
        <div class="weui-cell__bd">
          <input class="weui-input" type="text" name='card_number' id='card_number' placeholder="请输入身份证号" value=<?php echo ($targetAssistant["card_number"]); ?>>
        </div>
      </div>
      <div class="weui-cell weui-cell_select" style = "padding: 0;">
        <div class="weui-cell__bd">
          <p style = "padding-left: 15px;">性别</p>
        </div>
        <div class="weui-cell__bd">
          <select class="weui-select" name="sex" id='sex'>
          <?php if($targetAssistant["sex"] ==1): ?><option selected="selected" value="1">男</option>
         	 <option value="2">女</option>
          <?php else: ?>
           <option  value="1">男</option>
          	<option selected="selected" value="2">女</option><?php endif; ?>
           <!--  <option selected="" value="1">男</option>
            <option value="2">女</option> -->
          </select>
        </div>
      </div>
      <div class="weui-cell">
        <div class="weui-cell__hd"><label class="weui-label">年龄</label></div>
        <div class="weui-cell__bd">
            <input class="weui-input" type="number" name='age'id='age' pattern="[0-9]*" placeholder="请输入年龄" value=<?php echo ($targetAssistant["age"]); ?>>
        </div>
      </div>
     <!--  <div class="weui-cell">
        <div class="weui-cell__hd"><label class="weui-label">所属省</label></div>
        <div class="weui-cell__bd">
          <input class="weui-input" type="text"  name='belong_locations' id='belong_locations' placeholder="请输入所属省"  value=<?php echo ($targetAssistant["manage_locations"]); ?>>
        </div>
      </div> -->
    </div>
    <!-- 分配列表 -->
<section class="distribution-list qc-wrap" id="select-more">
   <div class="dis-list-wrap" id="select-list">
     <ul>下属省总
     <?php if(is_array($provinces)): $i = 0; $__LIST__ = $provinces;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$p): $mod = ($i % 2 );++$i; if($userId == $p['superior_id']): ?><li data-clinic_id='<?php echo ($p["id"]); ?>' class="selected">
     		<?php else: ?><li data-clinic_id='<?php echo ($p["id"]); ?>'><?php endif; ?>
          <i></i>
          <h6 class="name" style='margin-left:30px'><strong><?php echo ($p["real_name"]); ?></strong>
          </h6>
          <p class="sale-man">
          </p>
        </li><?php endforeach; endif; else: echo "" ;endif; ?>
     </ul>
   </div>
</section>
<!-- 分配列表 -->
    </form>
    <div class="weui-btn-area" style="background-color:#6db0e4;border-radius:5px">
	    <a class="weui-btn change_btn" href="javascript:">确定</a>
	  </div>
	</div>
	<div class="js_dialog" id="confirm_dialog" style="display: none;">
      <div class="weui-mask"></div>
      <div class="weui-dialog">
        <div class="weui-dialog__bd"></div>
        <div class="weui-dialog__ft">
            <a href="javascript:;" class="weui-dialog__btn weui-dialog__btn_primary">确 定</a>
        </div>
      </div>
    </div>
    <div class="js_dialog" id="iosDialog1" style="display: none;">
    <div class="weui-mask"></div>
    <div class="weui-dialog">
        <div class="weui-dialog__hd"><strong class="weui-dialog__title">提示</strong></div>
        <div class="weui-dialog__bd confir_content"></div>
        <div class="weui-dialog__ft">
            <a href="javascript:;" class="weui-dialog__btn weui-dialog__btn_default cancel-btn">取消</a>
            <a href="javascript:;" class="weui-dialog__btn weui-dialog__btn_primary ok-btn">确定</a>
        </div>
    </div>
</div>
 <div class="js_dialog" id="jsconfiroms" style="display: none;">
    <div class="weui-mask"></div>
    <div class="weui-dialog">
        <div class="weui-dialog__hd"><strong class="weui-dialog__title">提示</strong></div>
        <div class="weui-dialog__bd confir_content"></div>
        <div class="weui-dialog__ft">
            
            <a href="javascript:;" class="weui-dialog__btn weui-dialog__btn_primary oksss-btn">确定</a>
            <a href="javascript:;" class="weui-dialog__btn weui-dialog__btn_default cancelsss-btn">取消</a>
        </div>
    </div>
</div>


  <script type="text/javascript">
	var saleManagerStatus; //操作返回状态
	$(document).ready(function() { 
		saleManagerStatus='';
		saleManagerStatus ='<?php echo ($status); ?>';  //success,成功；error,错误
		msg ='<?php echo ($msg); ?>';
		if(saleManagerStatus=='success'||saleManagerStatus=='validatefail'){
			$('.weui-dialog__bd').html(msg);
     		$('#confirm_dialog').css('display','block');
     		//saleManagerStatus='formSubmitTrue';
		}
		if(saleManagerStatus=='error'){ 
			$('.weui-dialog__bd').html(msg);
     		$('#confirm_dialog').css('display','block');
     		//saleManagerStatus='formSubmitTrue';
		}
	}); 
	//关闭弹出框
	$(document).on('click','.weui-dialog__btn_primary',function(){
		$('#confirm_dialog').css('display','none');
		if(saleManagerStatus=='error'){
			history.go(-1);
		}
	}); 
	
	$(document).on('click','.cancelsss-btn',function(){
		$('#jsconfiroms').css('display','none');
	});
  </script>
</body>
<script src = "/Public/Home/SaleManager/js/Common.js"></script>
<script src = "/Public/Home/SaleManager/js/androidback.js"></script>
<script>
	/* $(document).on('click','.change_btn',function(){
		$('#addsale').submit();
	}) */
	var sessioncode;
	var nosesstion_url;
	var returnStatus;
	//返回操作
	$(document).on('click','.h_back',function(){
		location.href=document.referrer;
	})
	//删除事件
		$(document).on("click",".change_btn",function(){
			var reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/; 
		      var telReg = /^0?1[3|4|5|8][0-9]\d{8}$/;
		 
		      if (reg.test($("#card_number").val()) === false) { 
		    	  	$('.weui-dialog__bd').html('身份证输入不合法');
         		$('#confirm_dialog').css('display','block');
		         return false;  
		      };
		      if (telReg.test($("#phone").val()) === false) { 
		      //  $(".dialogCont").html("手机号输入不合法");
		        $('.weui-dialog__bd').html('手机号输入不合法');
         		$('#confirm_dialog').css('display','block');
		         return false;  
		      };
		      if ($("#age").val() < 1 || $("#age").val() > 200) {
		       // $(".dialogCont").html("年龄在1-200之间");
		        $('.weui-dialog__bd').html('年龄在1-200之间');
         		$('#confirm_dialog').css('display','block');
		        return false;
		      }
		      
		    //1.获取所有省总id
	     		clinicCheck='{';
	     		clinicObj=$('#select-list').find('.selected');
	     		if(clinicObj.length==0){
	     			$('.weui-dialog__bd').html('请选择省总');
    	     			$('#confirm_dialog').css('display','block');
	                 return false;
	     		}
	     		clinicObj.each(function(key,value){
	     			if(clinicObj.length-1==key){
	     				 clinicCheck+='"'+key+'":'+$(value).attr("data-clinic_id")+''
	     			}else{
	     				 clinicCheck+='"'+key+'":'+$(value).attr("data-clinic_id")+','
	     			}
	           	
	            });
	     		clinicCheck+='}';
		      var assistantUserId='<?php echo ($userId); ?>';
			$.ajax({
                url: "",
                type: 'POST',
                data: {'userId':assistantUserId,'real_name':$("#real_name").val(),'phone':$("#phone").val(),'card_number':$("#card_number").val(),'sex':$("#sex").val(),'age':$("#age").val(),'belong_locations':$("#belong_locations").val(),'t':'assistant','province':clinicCheck},
                async: false,
                cache: false,
               	dataType:"json",
                success: function (returndata) {
                	//session失效
               	 	returnStatus=returndata.code;
               	 	if(returndata.code==2028){
               	 		sessioncode=2028;
               	 		nosesstion_url=returndata.data;
	        	       	 	$('.weui-dialog__bd').html(returndata.msg);
	        	     		$('#confirm_dialog').css('display','block');
               	 	}else{
	               	 	$('.weui-dialog__bd').html(returndata.msg);
	             		$('#confirm_dialog').css('display','block');
               	 	}
                },
                error: function (returndata) {
                		$('.weui-dialog__bd').html(returndata.msg);
             		$('#confirm_dialog').css('display','block');
                }
            });
			$(document).on('click','.weui-dialog__btn_primary',function(){
				if(sessioncode==2028){
					window.location.href=nosesstion_url;
				}else{
					if(returnStatus==1){
						location.href='/Home/SaleManager/Salemanager/mySaleMan/t/assistant';
					}else{
						return false;
					}
					
				}
			})
		})
		$("#select-more").find("li").click(function(){
             var me=$(this);
             if(me.hasClass("selected")){
                 me.removeClass("selected")
             }
             else{
                 me.addClass("selected")
             }
         })
</script>
</html>